{% comment %}
/* Copyright 2009 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
{% endcomment %}
{% extends 'admin_base.html' %}
{% block content %}
{% if action %}
{% if confirmation %}
<div class="success">Update Completed!</div>
{% endif %}
<br><br>
  <form method="POST">
    <input type="hidden" name="post" value="{{post.key}}">
    <input type="hidden" name="author" value="{{user.key}}">
    <h3 id="main">Main</h3>
    <div id="main-content">
      <div class="table">
        <div class="row">
          <div class="cell label">
            Title*:
          </div>
          <div class="cell input">
            <input
              class="text-input"
              type="text"
              name="title"
              value="{{post.title|default_if_none:""|escape}}">
              {% if warnings.title %}<br>
              <span class="warning">Title is required.</span>
              {% endif %}
          </div>
        </div>
        <div class="row">
          <div class="cell label">
            Path:
          </div>
          <div class="cell input">
            <input
              type="text"
              name="path"
              class="text-input"
              value="{{post.path|addslashes}}">
              {% if warnings.path %}<br>
              <span class="warning">
                The path must be unique and not contain spaces.
              </span>
              {% endif %}
          </div>
        </div>
        <div class="row">
          <div class="cell label">
            Body*:
          </div>
          <div class="cell input">
            {% if warnings.body %}
            <span class="warning">Body is required.</span>
            {% endif %}
            <div id="content-editor-toolbar"></div>
            <div id="content-editor"></div>
            <textarea
              id="body"
              name="body">{{post.body|default_if_none:""|escape}}</textarea>
          </div>
        </div>
        <div class="row">
          <div class="cell label important">
            Published:
          </div>
          <div class="cell input">
            <input type="checkbox" name="is_published" value="true"
              {% if post.is_published %} checked="true" {% endif %}>
          </div>
        </div>
      </div>
    </div>
    
    <h3 id="meta" class="animated-zippy">Meta</h3>
    <div id="meta-content">
      <div class="table">
        <div class="row">
          <div class="cell label">
            Canonical:
          </div>
          <div class="cell input">
            <input
              type="text"
              name="canonical"
              class="text-input"
              value="{{post.canonical|default_if_none:""|escape}}">
              {% if warnings.canonical %}
              <span class="warning"><br>
                Please double check your canonical url.</span>
              {% endif %}
          </div>
        </div>
        <div class="row">
          <div class="cell label">
            Keywords:
          </div>
          <div class="cell input">
            <textarea class="textarea-small" name="keywords"
              >{{post.keywords|default_if_none:""|escape}}</textarea>
              (comma, separated, keywords)
              {% if warnings.keywords %}<br>
              <span class="warning">It appears there was a problem with your
                keywords.</span>
              {% endif %}
          </div>
        </div>
        <div class="row">
          <div class="cell label">
            Description:
          </div>
          <div class="cell input">
            <textarea class="textarea-med" name="description"
              >{{post.description|default_if_none:""|escape}}</textarea>
              {% if warnings.description %}<br>
              <span class="warning">It appears there was an issue with your
                description.</span>
              {% endif %}
          </div>
        </div>  
        <div class="row">
          <div class="cell label">
            NoIndex:
          </div>
          <div class="cell input">
            <input type="checkbox" name="noindex" value="true"
            {% if post.noindex %} checked="true" {% endif %}>
            {% if warnings.noindex %}<br>
            <span class="warning">This checkbox was not checked or unchecked
              properly.</span>
            {% endif %}
          </div>
        </div>
        <div class="row">
          <div class="cell label">
            NoFollow:
          </div>
          <div class="cell input">
            <input type="checkbox" name="nofollow" value="true"
            {% if post.nofollow %} checked="true" {% endif %}>
            {% if warnings.nofollow %}<br>
            <span class="warning">You might want to double check how you
              checked that checkbox.</span>
            {% endif %}
          </div>
        </div>
        <div class="row">
          <div class="cell label">
            NoArchive:
          </div>
          <div class="cell input">
            <input type="checkbox" name="noarchive" value="true"
              {% if post.noarchive %} checked="true" {% endif %}>
              {% if warnings.noarchive %}<br>
                <span class="warning">How do you mess up checking a box?</span>
              {% endif %}
          </div>
        </div>
        <div class="row">
          <div class="cell label">
            NoSnippet:
          </div>
          <div class="cell input">
            <input type="checkbox" name="nosnippet" value="true"
              {% if post.nosnippet %} checked="true" {% endif %}>
              {% if warnings.nosnippet %}<br>
                <span class="warning">How do you mess up checking a box?</span>
              {% endif %}
          </div>
        </div>
        <div class="row">
          <div class="cell label">
            NoODP:
          </div>
          <div class="cell input">
            <input
              type="checkbox"
              class="warning"
              name="noodp"
              {% if post.noodp %}
              checked="true"
              {% endif %}
              value="true">
              {% if warnings.noodp %}<br>
              <span class="warning">
                Your managed to mess up checking an unrequired
                checkbox. How'd you do that?</span>
              {% endif %}
          </div>
        </div>
      </div>
    </div>    
    <div class="table">
      <div class="row">
        <div class="cell label">
          <input type="submit" name="save" value="Save">
        </div>
        <div class="cell input">
          <input type="submit" name="done" value="Done">
          <input type="submit" name="cancel" value="Cancel">
          <span class="required important">* Required</span>
        </div>
      </div>
    </div>
  </form>
{% else %}
  <h3>
    <a href="/admin/posts?action=new" id="new-post-link">+ New Post</a>
  </h3>
  <div class="table">
      <div class="row">
        <div class="cell th">Action</div>
        <div class="cell th">Title</div>
        <div class="cell th">Author</div>
        <div class="cell th">Created</div>
        <div class="cell th">Edited</div>
        <div class="cell th">Published</div>
      </div>
    {% for post in posts %}
    {% ifequal post.author.gia user.gia %}
      <div class="row">
        <div class="cell">
          <a href='/admin/posts?action=edit&post={{post.key}}'>Edit</a> |
          <a href='/admin/posts?action=delete&post={{post.key}}'>Delete</a>
        </div>
        <div class="cell">
          <a
          href="/{{post.publish_date|date:"Y/m/d"}}/{{post.path|urlencode}}">
            {{post.title|truncatewords:8}}
          </a>
        </div>
        <div class="cell">
          {{post.author.nickname}}
        </div>
        <div class="cell">
          {{post.creation_date|date:"Y/m/d - g:i"}}
        </div>
        <div class="cell">
          {{post.edit_date|date:"Y/m/d  - g:i"}}
        </div>
        <div class="cell">
          {% if post.is_published %}
            {{post.publish_date|date:"Y/m/d  - g:i"}}
          {%else %}
            <span style="color:red">False</span>
          {% endif %}
        </div>
      </div>
      {% endifequal %}
      {% endfor %}
    </div>
{% endif %}
{% endblock %}